﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class Partner
    {
        public static void insert(PartnerEntity partner)
        {
            DbHelper.ExecuteNonQuery("p_Partner_insert",
                partner.AdminId,
                partner.Title,
                partner.Abbr,
                partner.Description,
                partner.ImgName,
                partner.Url,
                partner.Sort,
                partner.IsShow
            );
        }

        public static void update(PartnerEntity partner)
        {
            DbHelper.ExecuteNonQuery("p_Partner_update",
                partner.Pid,
                partner.AdminId,
                partner.Title,
                partner.Abbr,
                partner.Description,
                partner.ImgName,
                partner.Url,
                partner.Sort,
                partner.IsShow
            );
        }

        public static void delete(int pid)
        {
            DbHelper.ExecuteNonQuery("p_Partner_delete", pid);
        }

        public static PartnerEntity getById(int pid)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_partner_getById", pid);
            PartnerEntity partner = new PartnerEntity();
            if (dr != null)
            {
                partner.Pid = int.Parse(dr["pid"].ToString());
                partner.AdminId = int.Parse(dr["adminId"].ToString());
                partner.Title = dr["title"].ToString();
                partner.Abbr = dr["abbr"].ToString();
                partner.Description = dr["description"].ToString();
                partner.ImgName = dr["imgName"].ToString();
                partner.Url = dr["url"].ToString();
                partner.Sort = Convert.ToInt32(dr["sort"]);
                partner.IsShow = Convert.ToBoolean(dr["isShow"]);
                partner.InputDt = DateTime.Parse(dr["inputDt"].ToString());
            }
            return partner;
        }
    }
}